import BackTop from "components/content/backTop/BackTop";

import { debounce } from './utils'

export const itemListenerMixin = {
  data() {
    return {
      itemImageListener: null,
    }
  },
  mounted() {
    const refresh = debounce(this.$refs.scroll.refresh, 200);

    // 监听图片加载完成
    // Eventbus 事件通信
    this.itemImageListener = () => {
      refresh();
    };
    this.$bus.$on("imageLoad", this.itemImageListener);
  }
};

export const backTopMixin = {
  components: {
    BackTop,
  },
  data() {
    return {
      isShowBackTop: false,
    }
  },
  methods: {
    backClick() {
      this.$refs.scroll.scrollTo(0, 0);
    },
    listenShowBackTop(position) {
      this.isShowBackTop = -position.y > 1000
    }
  }
}

export const tabControlMixin = {
  data() {
    return {
      currentType: "pop"
    }
  },
  methods: {
    tabClick(index) {
      this.currentType = (index === 0 && "pop" || (index === 1) && "new" || (index === 2) && "sell")
    }
  }
}
